package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Agency;
import com.ruoyi.system.service.IAgencyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 代理管理Controller
 * 
 * @author ruoyi
 * @date 2024-10-23
 */
@RestController
@RequestMapping("/agency")
public class AgencyController extends BaseController
{
    @Autowired
    private IAgencyService agencyService;

    /**
     * 查询代理管理列表
     */
    @RequiresPermissions("agency:agency:list")
    @GetMapping("/list")
    public TableDataInfo list(Agency agency)
    {
        startPage();
        List<Agency> list = agencyService.selectAgencyList(agency);
        return getDataTable(list);
    }

    /**
     * 导出代理管理列表
     */
    @RequiresPermissions("agency:agency:export")
    @Log(title = "代理管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Agency agency)
    {
        List<Agency> list = agencyService.selectAgencyList(agency);
        ExcelUtil<Agency> util = new ExcelUtil<Agency>(Agency.class);
        util.exportExcel(response, list, "代理管理数据");
    }

    /**
     * 获取代理管理详细信息
     */
    @RequiresPermissions("agency:agency:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(agencyService.selectAgencyById(id));
    }

    /**
     * 新增代理管理
     */
    @RequiresPermissions("agency:agency:add")
    @Log(title = "代理管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Agency agency)
    {
        return toAjax(agencyService.insertAgency(agency));
    }

    /**
     * 修改代理管理
     */
    @RequiresPermissions("agency:agency:edit")
    @Log(title = "代理管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Agency agency)
    {
        return toAjax(agencyService.updateAgency(agency));
    }

    /**
     * 删除代理管理
     */
    @RequiresPermissions("agency:agency:remove")
    @Log(title = "代理管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(agencyService.deleteAgencyByIds(ids));
    }
}
